package com.it;

public class beerQuestion {
    public static int sum; //总酒数
    public static int lastBottle; //剩余瓶子
    public static int lastGlass; //剩余盖子

    public static void main(String[] args) {
        beer(10);
        System.out.println("总酒数：" + sum);
        System.out.println("剩余瓶子：" + lastBottle);
        System.out.println("剩余盖子：" + lastGlass);
    }

    /**
     * 啤酒问题
     * 啤酒2元一瓶，4个盖子换一瓶，2个空瓶换一瓶，求10元总共可以喝多少瓶
     *
     * @param n 钱数
     */
    public static void beer(int n) {
        //先把钱全花完
        int buyCount = n / 2;   //购买瓶子数
        sum += buyCount;
        //把酒喝完然后把盖子和空瓶换酒
        //计算本轮总的盖子和瓶子数
        int bottleCount = buyCount + lastBottle;
        int glassCount = buyCount + lastGlass;
        int sumMoney = 0;
        if (bottleCount >= 2) {
            sumMoney += (bottleCount / 2) * 2;
        }
        lastBottle = bottleCount % 2;
        if (glassCount >= 4) {
            sumMoney += (glassCount / 4) * 2;
        }
        lastGlass = glassCount % 4;
        if (sumMoney >= 2){
            beer(sumMoney);
        }
    }
}
